<template>
  <el-form ref="form" label-position="right" class="j-attribute-set" size="mini" label-width="80px">
    <el-form-item label="数据集">
      <el-select v-model="data.index" placeholder="选择数据集" @change="handleChange">
        <el-option :label="item.title" :value="index" v-for="(item,index) in gather" :key="index"></el-option>
      </el-select>
    </el-form-item>
    {{}}
    <el-form-item label="选择字段">
      <el-select v-model="data.field" placeholder="选择绑定字段">
        <el-option :label="item.title" :value="item.field" v-for="(item,index) in fields" :key="index"></el-option>
      </el-select>
    </el-form-item>
  </el-form>
</template>
<script type="text/javascript">
import { mapState, mapMutations, bootstrap } from 'vuecx'
export default {
  props: {
    value: [Array, Object, Number, String]
  },
  data() {
    return {

    };
  },
  computed: {
    ...mapState(['resources', 'main']),
    gather: function(argument) {
      console.log("this.main.libraries[1].attribute",this.main.libraries[1].attribute);
      return this.main.libraries[1].attribute.models;
    },
    data: function() {
      return this.value;
    },
    fields: function() {
      let index = this.data.index;
      if (this.gather.length === 0 || index === '') {
        return [];
      } else {
        return this.gather[index].fields;
      }
    }
  },
  watch: {
    data() {
      this.$emit('input', this.data)
    }
  },
  /**
   * 页面加载执行
   * @return {[type]} [description]
   */
  mounted() {
    let index = this.data.index ? this.data.index : 0;
    console.log("字体演技", this.gather);
    this.handleChange(index);
  },
  /**
   * 页面方法
   * @type {Object}
   */
  methods: {
    handleChange(index) {
      if (this.gather.length === 0 || index === '') {
        this.fields = []
      } else {
        this.data.gather = this.gather[index].name;
        this.fields = this.gather[index].fields;
      }
    }
  }

}

</script>
<style type="text/css" lang="scss">
.j-attribute-set {
  padding: 10px;
}

.el-form-item--mini.el-form-item,
.el-form-item--small.el-form-item {
  margin-bottom: 10px;
}

.el-form--label-top .el-form-item__label {
  float: none;
  display: inline-block;
  text-align: left;
  padding: 0;
}

</style>
